<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML" 4.01"//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- Created: August 17, 2001-->
<!--
$Id: RepMachine.php,v 1.7 2001/11/02 19:08:37 eugenem Exp eugenem $
$Header: /export/home/eugenem/public_html/ComplianceReports/RCS/RepMachine.php,v 1.7 2001/11/02 19:08:37 eugenem Exp eugenem $
$Log: RepMachine.php,v $
Revision 1.7  2001/11/02 19:08:37  eugenem
Moved HTTP_*_VARS processing to dbc.inc

Revision 1.6  2001/11/02 14:59:23  eugenem
Moved database connect statements to a separate file.

Revision 1.5  2001/10/25 15:21:53  eugenem
Added table to display survey information.
Added descriptive header tags to label each section.

Revision 1.4  2001/10/23 17:43:17  eugenem
Add ability to process HTTP_GET_VARS

Revision 1.3  2001/10/23 17:08:31  eugenem
Modified to display machine details.  Surveys by machine moved to RepSurvMachine.php.

Revision 1.2  2001/10/22 19:15:17  eugenem
Display Notes field in the report along with the machine description.

Revision 1.1  2001/08/17 16:18:46  eugenem
Initial revision

-->

<html>
<head>
<title>Radiological Equipment Database</title>
<meta name="author" content="Eugene Mah">
<link rev="made" href="mailto:eugenemah@gmail.com">
<link rev="home" href="http://imablog.net/">
<meta name="description" content="">
<meta name="Keywords" content="">
<meta name="Reply-to" content="eugenem@ix.netcom.com">
<META http-equiv="PICS-Label" content='(PICS-1.1 "http://www.classify.org/safesurf/" l r (SS~~0001))'>
<?PHP
require('functions.inc');
require('dbc.inc');

?>
</head>

<body>
<h1>Radiological Equipment Database</h1>
<h2>List Machine Information</h2>
<?PHP
if (isset($MachID)) {
  // Get the particular details on $MachID

  $query = "SELECT Description,Model,SerialNumber,ManufDate,InstallDate,
            Room,Notes,Modality,Manufacturer,Location,VendSiteID,
            IF(ManufDate<>\"0000-00-00\",
              PERIOD_DIFF(EXTRACT(YEAR_MONTH FROM CURRENT_DATE),EXTRACT(YEAR_MONTH FROM ManufDate))/12,
            IF(InstallDate<>\"0000-00-00\",
              PERIOD_DIFF(EXTRACT(YEAR_MONTH FROM CURRENT_DATE),EXTRACT(YEAR_MONTH FROM InstallDate))/12,
            \"N/A\")) AS Age 
            FROM Machines,Modality,Manufacturer,Location 
            WHERE MachineID=$MachID AND Machines.ModalityID=Modality.ModalityID 
            AND Machines.ManufacturerID=Manufacturer.ManufacturerID 
            AND Machines.LocationID=Location.LocationID";
  $machine = mysql_query($query)
    or die ("Unable to perform query: $query<br />\n" . mysql_error() . "<br />\n");
  $mach_row = mysql_fetch_array($machine);

  $desc = $mach_row['Description'];
  $note = $mach_row['Notes'];
  $siteID = $mach_row['VendSiteID'];
  if ($siteID=="0") $siteID="";
  
  // Get the details on any tubes for $MachID

  $query = "SELECT TubeID,HousingModel,HousingSN,InsertModel,InsertSN,
            ManufDate,LFS,MFS,SFS,Notes,HsgManuf.Manufacturer AS HManuf,
            InsManuf.Manufacturer AS IManuf,Notes, 
            IF(ManufDate<>\"0000-00-00\",
              PERIOD_DIFF(EXTRACT(YEAR_MONTH FROM CURRENT_DATE),EXTRACT(YEAR_MONTH FROM ManufDate))/12,
            IF(InstallDate<>\"0000-00-00\",
              PERIOD_DIFF(EXTRACT(YEAR_MONTH FROM CURRENT_DATE),EXTRACT(YEAR_MONTH FROM InstallDate))/12,
            \"N/A\")) AS Age 
            FROM Tubes,Manufacturer AS HsgManuf,Manufacturer AS InsManuf 
            WHERE MachineID=$MachID AND Status=\"Active\" 
            AND HousingManufID=HsgManuf.ManufacturerID 
            AND InsertManufID=InsManuf.ManufacturerID";
  $tubes = mysql_query($query)
  or die ("Unable to perform query: $query<br />\n" . mysql_error() . "<br />\n");

  // Get Operational Notes
  $query = "SELECT * FROM OperationalNotes WHERE MachineID=$MachID";
  $opnotes = mysql_query($query)
    or die ("Unable to perform query: $query<br />\n" . mysql_error() . "<br />\n");
?>
<h2><?PHP echo $mach_row['Modality'] . ": " . $desc . " (" . $siteID . ")"; ?></h2>
<h3>Machine information</h3>
<p>
<b>Machine ID:</b> <?php echo $MachID ?> <br />
<b>Model:</b> <?PHP echo $mach_row['Manufacturer'] . " " . $mach_row['Model']; ?> 
<b>Serial Number:</b> <?PHP echo $mach_row['SerialNumber']; ?> 
<b>Vendor Site ID:</b> <?PHP echo $mach_row['VendSiteID']; ?><br />
<b>Location:</b> <?PHP echo $mach_row['Location'] . " " . $mach_row['Room']; ?><br />
<b>Manufacture Date:</b> <?PHP echo $mach_row['ManufDate']<>"0000-00-00"?$mach_row['ManufDate']:"NA"; ?> 
<b>Install Date:</b> <?PHP echo $mach_row['InstallDate']<>"0000-00-00"?$mach_row['InstallDate']:"NA"; ?> 
<b>Age:</b> <?PHP echo $mach_row['Age']; ?> years<br />
<b>Notes:</b> <?PHP echo $note; ?><br />
</p>
<h3>Tube information</h3>

<table border=1>
  <tr>
    <th>Tube ID</th>
    <th>Housing</th>
    <th>Housing SN</th>
    <th>Insert</th>
    <th>Insert SN</th>
    <th>Focal Spots</th>
    <th>Manuf Date</th>
    <th>Age</th>
  <th>Notes</th>
  </tr>
<?PHP
  // Spit the results out into a table
  while ($tube_row = mysql_fetch_array($tubes)) {
    echo "<tr>\n";
    echo "<td>" . $tube_row['TubeID'] . "</td>\n";
    echo "<td>" . $tube_row['HManuf'] . " " . $tube_row['HousingModel'] . "</td>\n";
    echo "<td>" . $tube_row['HousingSN'] . "</td>\n";
    echo "<td>" . $tube_row['IManuf'] . " " . $tube_row['InsertModel'] . "</td>\n";
    echo "<td>" . $tube_row['InsertSN'] . "</td>\n";
    echo "<td>" . $tube_row['LFS'] . "/" . $tube_row['MFS'] . "/" . $tube_row['SFS'] . "</td>\n";
    echo "<td>" . $tube_row['ManufDate'] . "</td>\n";
    echo "<td>" . $tube_row['Age'] . "</td>\n";
  echo "<td>" . $tube_row['Notes'] . "</td>\n";
    echo "</tr>\n";
  }
?>

</table>

<?PHP
  // Get survey information for this machine
  $query = "SELECT Survey2Machine.SurveyID,TestDate,TestType,Accession,Notes 
            FROM Survey2Machine 
            LEFT JOIN TestDates USING (SurveyID),TestType 
            WHERE Survey2Machine.MachineID=$MachID 
            AND TestType.TypeID=TestDates.TypeID 
            ORDER BY TestDate";

  $survey = mysql_query($query)
    or die ("Unable to perform query: $query<br />\n" . mysql_error() . "<br />\n");

  echo "<h3>Survey information</h3>";
  echo "<table border='1'>";
  echo "  <tr>";
  echo "    <th>SurveyID</th><th>TestDate</th><th>TestType</th><th>Accession</th><th>Notes</th>";
  echo "  </tr>";

  // Spit the results out into a table
  while ($row = mysql_fetch_array($survey)) {
    echo "<tr>\n";
    echo "<td><a href=\"SurveyResRec.php?SurveyID=" . $row['SurveyID'] . "\">" . $row['SurveyID'] . "</a></td>\n";
    echo "<td>" . $row['TestDate'] . "</td>\n";
    echo "<td>" . $row['TestType'] . "</td>\n";
    echo "<td>" . $row['Accession'] . "</td>\n";
    echo "<td>" . $row['Notes'] . "</td>\n";
    echo "<tr>\n";
  }
  echo "<tr>\n";
  echo "<td><a href='SurveyAdd.php?MachID=$MachID'>Add Survey</a></td>\n";
  echo "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>\n";
  echo "</tr>\n";
  echo "</table>\n";
  
  // Output operational notes
  echo "<h3>Operational Notes</h3>\n";
  echo "<ol>\n";
  while ($row = mysql_fetch_array($opnotes)) {
    echo "  <li>" . $row['Note'] . "</li>\n";
  }
  echo "</ol>\n";
}
?>
<form action="RepMachine.php" method="POST">
<p>Select machine:
<?PHP
$mach_sel = mysql_query("select MachineID,Description from Machines where Status=\"Active\" order by Description");
echo listbox_field($mach_sel,"MachID","");
?>
</p>
<p><input type="SUBMIT" value="Search"> / <input type="RESET" value="Reset"> / <a href="index.html" target="_top" >Main</a></p>
</form>
</body>
</html>
